package com.lixiang.service.impl;

import com.lixiang.dao.EmpDao;
import com.lixiang.entity.Emp;
import com.lixiang.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.util.UUID;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpDao empDao;
    @Override
    public ModelAndView login(String name, String password) {
        Emp emp = empDao.findByName(name);
        ModelAndView modelAndView=new ModelAndView();
        if(emp!=null){
            modelAndView.addObject(emp);
            modelAndView.setViewName("success.jsp");
        }
        return modelAndView;
    }

    @Override
    public ModelAndView regist(Emp emp) {
        emp.setId(UUID.randomUUID().toString());
        empDao.insert(emp);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject(emp);
        modelAndView.setViewName("success.jsp");
        return modelAndView;
    }
}
